package com.khalil.kkadmin.infrastructure.jpa;

import com.khalil.kkadmin.common.util.StrUtil;
import com.khalil.kkadmin.infrastructure.web.security.WebContext;
import org.jetbrains.annotations.NotNull;
import org.springframework.data.domain.AuditorAware;

import java.util.Optional;

public class DefaultWebAuditorAware implements AuditorAware<String> {
    @NotNull
    @Override
    public Optional<String> getCurrentAuditor() {
        String username = WebContext.getUsername();
        return Optional.of(StrUtil.isEmpty(username) ? "default" : username);
    }
}
